<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div class="p">我是父亲
        <div class="s">
            我是100孙子
        </div>
    </div>
</body>
<!--模版-->
<script id="tmp" type="text/html">
    {{each data1 as value i }}
    <div class="p">
        {{value.pname}}
        <div class="s">
            {{getNum(value.sname)}}
        </div>
    </div>
    {{/each}}
</script>
<script src="../js/template.js"></script>
<!--<script src="../lib/jquery/jquery.js"></script>-->
<script>
    function getNum(str) {
        // console.dir(/\d+/.exec(str));
        return /\d+/.exec(str)[0];
    }


    template.helper("getNum", getNum);

    var datas = [{
        pname: 11,
        sname: "我是100孙子"
    }, {
        pname: 111,
        sname: "我是100孙子"
    }, {
        pname: 1111,
        sname: "我是100孙子"
    }, {
        pname: 1111,
        sname: "我是100孙子"
    }];

    var obj = {
        data1: datas
    };

    var html = template("tmp", obj);
    document.body.innerHTML = html;
</script>

</html>